﻿using INTEX.DataBase.Tools;
using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Timers;
using System.Windows;
namespace WPFExcelReport
{
    /// <summary>
    /// Interaction logic for SETUPABON.xaml
    /// </summary>
    public partial class TITXUPDATE
    {

        public TITXUPDATE()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VICC_FOLDERS();
            this.DataContext = MV;
            InitializeComponent();
            if (VAR == "")
                VAR = "5";
            MV.OnMessage += MV_OnMessage;
            OnLineTimer = new Timer();
            OnLineTimer.Interval = 1000 * 60 * int.Parse(VAR);
            OnLineTimer.Elapsed += OnLineTimer_Elapsed;
            OnLineTimer.Start();

        }
        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            if (IsLoaded)
                return;
            
            base.Window_Loaded(sender, e);
        }
        private void MV_OnMessage(object sender, MessageEventArgs e)
        {
            INFO= e.Info.Details+Environment.NewLine+ INFO;
        }
        public override void bgWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            TMV.ITXUPDATE(TMV.ART);
            base.bgWorker_DoWork(sender, e);
        }
        public override void bgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            IsBusy = false;
            base.bgWorker_RunWorkerCompleted(sender, e);
        }
        Timer OnLineTimer;
        public override void NewCommand(object sender, RoutedEventArgs e)
        {
            INFO = "开始更新";
            IsBusy = true;
            bgWorker.RunWorkerAsync();
        }
        bool IsRun = false;
        void OnLineTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            try
            {
                if (IsBusy)
                    return;
                if (IsRun)
                    return; 
                IsRun = true;
                TMV.CHKUPDATE();
                IsRun = false;
            }
            catch (Exception ex)
            {
            }
        }
    }
}
